class OfficeCenterFilterArguments {
  String? type; // task taskcompleted read readcompleted
  OfficeCenterFilterBody? result;

  OfficeCenterFilterArguments({this.type, this.result});

  Map<String, dynamic> toJson() {
    return {'type': type, 'result': result?.toJson()};
  }

  factory OfficeCenterFilterArguments.fromJson(Map<String, dynamic> json) {
    return OfficeCenterFilterArguments(
        type: json['type'],
        result: json['result'] == null
            ? null
            : OfficeCenterFilterBody.fromJson(json['result']));
  }
}

class OfficeCenterFilterBody {
  List<String>? applicationList;
  List<String>? processList;
  List<String>? creatorUnitList;
  List<String>? startTimeMonthList;
  List<String>? completedTimeMonthList;
  List<String>? activityNameList;
  List<bool>? completedList;
  String? key;

  OfficeCenterFilterBody(
      {this.key,
      this.applicationList,
      this.processList,
      this.creatorUnitList,
      this.startTimeMonthList,
      this.completedTimeMonthList,
      this.activityNameList,
      this.completedList});

  /// 是否有添加过滤条件
  bool hasFilter() {
    final aCount = applicationList?.length ?? 0;
    final pCount = processList?.length ?? 0;
    final uCount = creatorUnitList?.length ?? 0;
    final sCount = startTimeMonthList?.length ?? 0;
    final ctCount = completedTimeMonthList?.length ?? 0;
    final atCount = activityNameList?.length ?? 0;
    final cCount = completedList?.length ?? 0;
    return (aCount + pCount + uCount + sCount + ctCount + atCount + cCount) > 0;
  }

  // copyWith 方法实现
  void copyFrom(OfficeCenterFilterBody origin) {
    key = origin.key;
    applicationList = origin.applicationList;
    processList = origin.processList;
    creatorUnitList = origin.creatorUnitList;
    startTimeMonthList = origin.startTimeMonthList;
    completedTimeMonthList = origin.completedTimeMonthList;
    activityNameList = origin.activityNameList;
    completedList = origin.completedList;
  }

  // 可以选择添加一个toJson方法来支持序列化
  Map<String, dynamic> toJson() {
    return {
      'key': key,
      'applicationList': applicationList,
      'processList': processList,
      'creatorUnitList': creatorUnitList,
      'startTimeMonthList': startTimeMonthList,
      'completedTimeMonthList': completedTimeMonthList,
      'activityNameList': activityNameList,
      'completedList': completedList,
    };
  }

  factory OfficeCenterFilterBody.fromJson(Map<String, dynamic> json) {
    return OfficeCenterFilterBody(
      key: json['key'],
      applicationList:
          (json['applicationList'] as List?)?.map((e) => e.toString()).toList(),
      processList:
          (json['processList'] as List?)?.map((e) => e.toString()).toList(),
      creatorUnitList:
          (json['creatorUnitList'] as List?)?.map((e) => e.toString()).toList(),
      startTimeMonthList: (json['startTimeMonthList'] as List?)
          ?.map((e) => e.toString())
          .toList(),
      completedTimeMonthList: (json['completedTimeMonthList'] as List?)
          ?.map((e) => e.toString())
          .toList(),
      activityNameList: (json['activityNameList'] as List?)
          ?.map((e) => e.toString())
          .toList(),
      completedList:
          (json['completedList'] as List?)?.map((e) => e as bool).toList(),
    );
  }
}

class OfficeCenterFilterAttribute {
  List<OfficeCenterFilterAttributeItem>? applicationList; // 可选择的应用
  List<OfficeCenterFilterAttributeItem>? processList; // 可选择的流程
  List<OfficeCenterFilterAttributeItem>? creatorUnitList; // 可选择的组织
  List<OfficeCenterFilterAttributeItem>? startTimeMonthList; // 可选择的开始月份
  List<OfficeCenterFilterAttributeItem>? completedTimeMonthList; // 可选择的结束月份
  List<OfficeCenterFilterAttributeItem>? activityNameList; // 可选择的活动节点
  List<OfficeCenterFilterAttributeItem>? completedList; // 可选择的完成状态

  OfficeCenterFilterAttribute({
    this.applicationList,
    this.processList,
    this.creatorUnitList,
    this.startTimeMonthList,
    this.completedTimeMonthList,
    this.activityNameList,
    this.completedList,
  });

  // 可以选择添加一个toJson方法来支持序列化
  Map<String, dynamic> toJson() {
    return {
      'applicationList': applicationList?.map((e) => e.toJson()).toList(),
      'processList': processList?.map((e) => e.toJson()).toList(),
      'creatorUnitList': creatorUnitList?.map((e) => e.toJson()).toList(),
      'startTimeMonthList': startTimeMonthList?.map((e) => e.toJson()).toList(),
      'completedTimeMonthList':
          completedTimeMonthList?.map((e) => e.toJson()).toList(),
      'activityNameList': activityNameList?.map((e) => e.toJson()).toList(),
      'completedList': completedList?.map((e) => e.toJson()).toList(),
    };
  }

  // 可以选择添加一个fromJson方法来支持反序列化
  factory OfficeCenterFilterAttribute.fromJson(Map<String, dynamic> json) {
    return OfficeCenterFilterAttribute(
      applicationList: (json['applicationList'] as List?)
          ?.map((e) => OfficeCenterFilterAttributeItem.fromJson(e))
          .toList(),
      processList: (json['processList'] as List?)
          ?.map((e) => OfficeCenterFilterAttributeItem.fromJson(e))
          .toList(),
      creatorUnitList: (json['creatorUnitList'] as List?)
          ?.map((e) => OfficeCenterFilterAttributeItem.fromJson(e))
          .toList(),
      startTimeMonthList: (json['startTimeMonthList'] as List?)
          ?.map((e) => OfficeCenterFilterAttributeItem.fromJson(e))
          .toList(),
      completedTimeMonthList: (json['completedTimeMonthList'] as List?)
          ?.map((e) => OfficeCenterFilterAttributeItem.fromJson(e))
          .toList(),
      activityNameList: (json['activityNameList'] as List?)
          ?.map((e) => OfficeCenterFilterAttributeItem.fromJson(e))
          .toList(),
      completedList: (json['completedList'] as List?)
          ?.map((e) => OfficeCenterFilterAttributeItem.fromJson(e))
          .toList(),
    );
  }
}

class OfficeCenterFilterAttributeItem {
  String? name;
  dynamic value;

  OfficeCenterFilterAttributeItem({this.name, this.value});

  // 将对象转换为Map，支持序列化
  Map<String, dynamic> toJson() {
    return {
      'name': name,
      'value': value,
    };
  }

  // 从Map反序列化为对象
  factory OfficeCenterFilterAttributeItem.fromJson(Map<String, dynamic> json) {
    return OfficeCenterFilterAttributeItem(
      name: json['name'],
      value: json['value'],
    );
  }
}
